﻿import idv.ben.gc4flash.chart.*;
import idv.ben.gc4flash.dataLine.*;
import idv.ben.gc4flash.encode.*;
import idv.ben.gc4flash.fill.*;
import idv.ben.gc4flash.util.*;
/**
* 圓餅圖。<br>
* 參考 Google Chart API：<a href="http://code.google.com/apis/chart/#pie_charts" target="_blank">http://code.google.com/apis/chart/#pie_charts</a><br>
*/
class idv.ben.gc4flash.chart.PieChart extends AbstractChart {
	private var labels:Array;
	/**
	* 圓餅圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=p&chd=s:Uf9a&chs=200x100&chl=January|February|March|April"><br>
	* cht=p
	*/
	public static var CHART_TYPE_PieChart_2D:String = "p";
	/**
	* 3D圓餅圖<br>
	* <img src="http://chart.apis.google.com/chart?cht=p3&chd=s:Uf9a&chs=250x100&chl=January|February|March|April"><br>
	* cht=p3
	*/
	public static var CHART_TYPE_PieChart_3D:String = "p3";
	/**
	* 建構子
	* @param w 圖檔寬度
	* @param h 圖檔高度
	* @param typ 圖形種類，包括：<br>
	* {@link #CHART_TYPE_PieChart_2D} = "p"<br>
	* {@link #CHART_TYPE_PieChart_3D} = "p3"<br>
	*/
	function PieChart(w:Number, h:Number, typ:String) {
		super(w, h);
		if (typ == CHART_TYPE_PieChart_2D || typ == CHART_TYPE_PieChart_3D) {
			this.typ = typ;
		} else {
			throw new Error("chart type error!!");
		}
		allowParams = Const.CHT_PARAM_Pie_chart;
	}
	/**
	* 設定圓餅圖資料
	* @param values 圓餅圖資料的數值陣列，[n1:Number, n2:Number, ..., nN:Number]
	* <img src="http://chart.apis.google.com/chart?cht=p3&chs=220x100&chd=s:Hellob&chl=May|Jun|Jul|Aug|Sep|Oct"><br>
	* chl=May|Jun|Jul|Aug|Sep|Oct<br>
	*/
	public function setLine(values:Array):Void {
		var ds:ChartDataSet = new ChartDataSet();
		for(var i:Number=0; i<values.length; i++){
			ds.addValue(values[i]);
		}
		var dataLine:DataLine = new DataLine([ds]);
		lines = [{line:dataLine}];
	}
	/**
	* 設定圖示說明
	* @param labels 圖示說明文字陣列，["圖示1", "圖示2", ..., "圖示n"]<br>
	* <img src="http://chart.apis.google.com/chart?cht=p3&chs=220x100&chd=s:Hellob&chl=May|Jun|Jul|Aug|Sep|Oct"><br>
	* chl=May|Jun|Jul|Aug|Sep|Oct<br>
	*/
	public function setLabels(labels:Array):Void{
		this.labels = labels;
	}
	/**
	* 取得圖示說明所組成的 URL 參數字串
	* @return URL 參數字串
	**/
	public function getLabelsChartData():String{
		if(labels!=null && labels.length>0){
			return "&chl=" + labels.join("|");
		}else{
			return "";
		}
	}
}
